package com.powerbank.adminsystem.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.powerbank.adminsystem.entity.AdminUser;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * 管理员用户Mapper接口
 */
@Mapper
public interface AdminUserMapper extends BaseMapper<AdminUser> {

    /**
     * 根据用户名查询用户
     */
    @Select("SELECT * FROM admin_user WHERE username = #{username} AND deleted = 0")
    AdminUser findByUsername(@Param("username") String username);

    /**
     * 根据邮箱查询用户
     */
    @Select("SELECT * FROM admin_user WHERE email = #{email} AND deleted = 0")
    AdminUser findByEmail(@Param("email") String email);

    /**
     * 根据手机号查询用户
     */
    @Select("SELECT * FROM admin_user WHERE phone = #{phone} AND deleted = 0")
    AdminUser findByPhone(@Param("phone") String phone);

    /**
     * 更新用户最后登录信息
     */
    int updateLastLoginInfo(@Param("id") Long id, @Param("lastLoginTime") java.time.LocalDateTime lastLoginTime, 
                           @Param("lastLoginIp") String lastLoginIp);
}